package Longing;

import java.sql.*;

/**
 * @Author 枫城
 * @Date 2022/4/7
 * @Param 测试封装的工具 DBUtil
 *          实现模糊查询
 * @return
 **/

public class demo7 {
    public static void main(String[] args) {
        Connection connection = null;
        PreparedStatement ps = null;
        ResultSet resultSet = null;
        try {
            // 获取连接
            connection = demo6.DBUtil.getConnection();
            // 获取预编译对象
            String sql = "select * from user  where combat_value >= 40000";
            ps = connection.prepareStatement(sql);

            resultSet = ps.executeQuery();
            while (resultSet.next()){
                String a = resultSet.getString("user_id");  // 注意sql语句的as，根据sql语句语句来转换
                String b = resultSet.getString("user_name");
                String c = resultSet.getString("pwd");
                String d = resultSet.getString("user_rename");
                String e = resultSet.getString("combat_value");
                System.out.println(a + " | " + b + " | " + c + " | " + d +" | "+ e );
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            // 释放资源
            demo6.DBUtil.close(connection, ps, resultSet);
        }

    }

}
